# use normal make for this Makefile
#
# Makefile for building user programs to run on top of Nachos
#
# Several things to be aware of:
#
#    Nachos assumes that the location of the program startup routine (the
# 	location the kernel jumps to when the program initially starts up)
#       is at location 0.  This means: start.o must be the first .o passed 
# 	to ld, in order for the routine "Start" to be loaded at location 0
#

# If you are running on SunOS 5.x machines, uncomment the next line
GCCDIR = /auto/home-scf-22/csci402/testgnu/decstation-ultrix/bin/
LDFLAGS = -T newscript -N
ASFLAGS = -mips1
CPPFLAGS = $(INCDIR)

# if you aren't cross-compiling:
# GCCDIR =
# LDFLAGS = -N -T 0
# ASFLAGS =
# CPPFLAGS = -P $(INCDIR)


CC = $(GCCDIR)gcc
AS = $(GCCDIR)as
LD = $(GCCDIR)ld
CPP = $(GCCDIR)cpp

INCDIR =-I../userprog -I../threads
CFLAGS = -G 0 -c $(INCDIR)

all: halt matmult sort testfiles max_exec_test max_exec_program max_fork_test max_execfork_test homedepot homedepot2 syscall_test1 syscall_test2 syscall_test3 syscall_test4 syscall_test5 syscall_test5_program0 syscall_test5_program1 networktest networktest_wait networktest_signal networktest_broadcast networktest_error

start.o: start.s ../userprog/syscall.h
	$(CPP) $(CPPFLAGS) start.s > strt.s
	$(AS) $(ASFLAGS) -o start.o strt.s
	rm strt.s

halt.o: halt.c
	$(CC) $(CFLAGS) -c halt.c
halt: halt.o start.o
	$(LD) $(LDFLAGS) start.o halt.o -o halt.coff
	../bin/coff2noff halt.coff halt

sort.o: sort.c
	$(CC) $(CFLAGS) -c sort.c
sort: sort.o start.o
	$(LD) $(LDFLAGS) start.o sort.o -o sort.coff
	../bin/coff2noff sort.coff sort

matmult.o: matmult.c
	$(CC) $(CFLAGS) -c matmult.c
matmult: matmult.o start.o
	$(LD) $(LDFLAGS) start.o matmult.o -o matmult.coff
	../bin/coff2noff matmult.coff matmult

testfiles.o: testfiles.c
	$(CC) $(CFLAGS) -c testfiles.c
testfiles: testfiles.o start.o
	$(LD) $(LDFLAGS) start.o testfiles.o -o testfiles.coff
	../bin/coff2noff testfiles.coff testfiles

syscall_test1.o: syscall_test1.c
	$(CC) $(CFLAGS) -c syscall_test1.c
syscall_test1: syscall_test1.o start.o
	$(LD) $(LDFLAGS) start.o syscall_test1.o -o syscall_test1.coff
	../bin/coff2noff syscall_test1.coff syscall_test1

syscall_test2.o: syscall_test2.c
	$(CC) $(CFLAGS) -c syscall_test2.c
syscall_test2: syscall_test2.o start.o
	$(LD) $(LDFLAGS) start.o syscall_test2.o -o syscall_test2.coff
	../bin/coff2noff syscall_test2.coff syscall_test2

syscall_test3.o: syscall_test3.c
	$(CC) $(CFLAGS) -c syscall_test3.c
syscall_test3: syscall_test3.o start.o
	$(LD) $(LDFLAGS) start.o syscall_test3.o -o syscall_test3.coff
	../bin/coff2noff syscall_test3.coff syscall_test3

syscall_test4.o: syscall_test4.c
	$(CC) $(CFLAGS) -c syscall_test4.c
syscall_test4: syscall_test4.o start.o
	$(LD) $(LDFLAGS) start.o syscall_test4.o -o syscall_test4.coff
	../bin/coff2noff syscall_test4.coff syscall_test4

#DUMMY PART
dummy.o: dummy.c
	$(CC) $(CFLAGS) -c dummy.c
dummy: dummy.o start.o
	$(LD) $(LDFLAGS) start.o dummy.o -o dummy.coff
	../bin/coff2noff dummy.coff dummy
#DUMMY PART ENDS

#doctoroffice
#doctoroffice.o: doctoroffice.c
#	$(CC) $(CFLAGS) -c doctoroffice.c
#homedepot: doctoroffice.o start.o
#	$(LD) $(LDFLAGS) start.o doctoroffice.o -o doctoroffice.coff
#	../bin/coff2noff doctoroffice.coff doctoroffice

#homedepot
#Trying to run just 1 Home Depot Simulation
homedepot.o: homedepot.c
	$(CC) $(CFLAGS) -c homedepot.c
homedepot: homedepot.o start.o
	$(LD) $(LDFLAGS) start.o homedepot.o -o homedepot.coff
	../bin/coff2noff homedepot.coff homedepot

#homedepot2
#Trying to exec 2 Home Depot Simulation
homedepot2.o: homedepot2.c
	$(CC) $(CFLAGS) -c homedepot2.c
homedepot2: homedepot2.o start.o
	$(LD) $(LDFLAGS) start.o homedepot2.o -o homedepot2.coff
	../bin/coff2noff homedepot2.coff homedepot2


#max_exec_test
#Trying to exec the maximum + some processes
max_exec_test.o: max_exec_test.c
	$(CC) $(CFLAGS) -c max_exec_test.c
max_exec_test: max_exec_test.o start.o
	$(LD) $(LDFLAGS) start.o max_exec_test.o -o max_exec_test.coff
	../bin/coff2noff max_exec_test.coff max_exec_test

#max_exec_program
#Dummy program for max_exec_test
max_exec_program.o: max_exec_program.c
	$(CC) $(CFLAGS) -c max_exec_program.c
max_exec_program: max_exec_program.o start.o
	$(LD) $(LDFLAGS) start.o max_exec_program.o -o max_exec_program.coff
	../bin/coff2noff max_exec_program.coff max_exec_program

#max_fork_test
#Trying to fork the maximum + some threads
max_fork_test.o: max_fork_test.c
	$(CC) $(CFLAGS) -c max_fork_test.c
max_fork_test: max_fork_test.o start.o
	$(LD) $(LDFLAGS) start.o max_fork_test.o -o max_fork_test.coff
	../bin/coff2noff max_fork_test.coff max_fork_test

#max_execfork_test
#Trying to exec the maximum + some processes, then fork the maximum + some threads
max_execfork_test.o: max_execfork_test.c
	$(CC) $(CFLAGS) -c max_execfork_test.c
max_execfork_test: max_execfork_test.o start.o
	$(LD) $(LDFLAGS) start.o max_execfork_test.o -o max_execfork_test.coff
	../bin/coff2noff max_execfork_test.coff max_execfork_test

#syscall_test5
#Trying to exec two processes, each trying to use the other's locks/conditions
syscall_test5.o: syscall_test5.c
	$(CC) $(CFLAGS) -c syscall_test5.c
syscall_test5: syscall_test5.o start.o
	$(LD) $(LDFLAGS) start.o syscall_test5.o -o syscall_test5.coff
	../bin/coff2noff syscall_test5.coff syscall_test5

syscall_test5_program0.o: syscall_test5_program0.c
	$(CC) $(CFLAGS) -c syscall_test5_program0.c
syscall_test5_program0: syscall_test5_program0.o start.o
	$(LD) $(LDFLAGS) start.o syscall_test5_program0.o -o syscall_test5_program0.coff
	../bin/coff2noff syscall_test5_program0.coff syscall_test5_program0

syscall_test5_program1.o: syscall_test5_program1.c
	$(CC) $(CFLAGS) -c syscall_test5_program1.c
syscall_test5_program1: syscall_test5_program1.o start.o
	$(LD) $(LDFLAGS) start.o syscall_test5_program1.o -o syscall_test5_program1.coff
	../bin/coff2noff syscall_test5_program1.coff syscall_test5_program1

networktest.o: networktest.c
	$(CC) $(CFLAGS) -c networktest.c
networktest: networktest.o start.o
	$(LD) $(LDFLAGS) start.o networktest.o -o networktest.coff
	../bin/coff2noff networktest.coff networktest
clean:
	rm -f *.o *.coff

networktest_wait.o: networktest_wait.c
	$(CC) $(CFLAGS) -c networktest_wait.c
networktest_wait: networktest_wait.o start.o
	$(LD) $(LDFLAGS) start.o networktest_wait.o -o networktest_wait.coff
	../bin/coff2noff networktest_wait.coff networktest_wait
clean:
	rm -f *.o *.coff
	
networktest_signal.o: networktest_signal.c
	$(CC) $(CFLAGS) -c networktest_signal.c
networktest_signal: networktest_signal.o start.o
	$(LD) $(LDFLAGS) start.o networktest_signal.o -o networktest_signal.coff
	../bin/coff2noff networktest_signal.coff networktest_signal
clean:
	rm -f *.o *.coff
	
networktest_broadcast.o: networktest_broadcast.c
	$(CC) $(CFLAGS) -c networktest_broadcast.c
networktest_broadcast: networktest_broadcast.o start.o
	$(LD) $(LDFLAGS) start.o networktest_broadcast.o -o networktest_broadcast.coff
	../bin/coff2noff networktest_broadcast.coff networktest_broadcast
clean:
	rm -f *.o *.coff
	
networktest_error.o: networktest_error.c
	$(CC) $(CFLAGS) -c networktest_error.c
networktest_error: networktest_error.o start.o
	$(LD) $(LDFLAGS) start.o networktest_error.o -o networktest_error.coff
	../bin/coff2noff networktest_error.coff networktest_error
clean:
	rm -f *.o *.coff